<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0px;
            padding: 0px;
        }

        .a1 {
            width: 500px;
            height: 600px;
            /* border: 1px solid red; */
            margin: 100px auto;

        }

        .a2 {
            font-size: 20px;
            font-weight: bold;
            width: 100px;
            height: 40px;
            /* border: 1px solid blue; */
            text-align: center;
            line-height: 40px;
            margin: 0px auto;

        }

        .a3 {
            width: 480px;
            height: 540px;
            border: 1px solid #536595;
            margin: 10px auto;
            background-color: #536595;
            box-shadow: 20px 20px 5px #cccccc;
        }

        .a4 {
            width: 480px;
            height: 40px;
            display: flex;
            /* border: 1px solid red; */
            justify-content: space-around;
            margin-top: 30px;

        }

        .a5 {
            line-height: 40px;
            /* margin-left: 20px; */
            color: white;
        }

        .a6 {
            width: 300px;
            height: 30px;
            /* margin-left: 40px; */
            margin-top: 7px;
            border-radius: 5px;
            border: white;
        }

        input{
            outline: 0;
          
        }
        .a4 input,.b3 input{
            text-indent: 10px;
        }
        .b1 {
            line-height: 40px;
            /* margin-left: 20px; */
            color: white;
        }

        .b2 {
            width: 300px;
            height: 30px;
            /* margin-left: 40px; */
            margin-top: 7px;
            border-radius: 5px;
            border: white;
        }

        .b3 {
            width: 480px;
            height: 40px;
            display: flex;
            /* border: 1px solid red; */
            margin-top: 60px;
            justify-content: space-around;
        }

        .b4 {
            width: 480px;
            height: 80px;
            /* border: 1px red solid; */
            margin-top: 40px;
            display: flex;
            justify-content: space-evenly;
            align-items: center;
        }

        .b4 input {
            outline: none;
        }

        .b4 input:active {
            background-color: hotpink;
        }

        .b5 {
            width: 80px;
            height: 60px;
            border-radius: 7px;
            background-color: white;
            border: white;
        }

        .c1 {
            width: 480px;
            height: 40px;
            display: flex;
            /* border: 1px solid red; */
            margin-top: 30px;
            justify-content: space-around;
        }

        .c2 {
            line-height: 40px;
            margin-left: 20px;
            color: white;

        }

        .c3 {
            width: 300px;
            height: 30px;
            /* margin-left: 40px; */
            margin-top: 7px;
            border-radius: 5px;
            border: white;
        }

        .c4 {
            width: 480px;
            height: 150px;
            /* border: 1px solid red; */
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .c4 input:active {
            background-color: red;
            outline: none;
        }

        .c5 {
            width: 70px;
            height: 40px;
            /* margin-top: 60px; */
            /* margin-left: 208px; */
            font-weight: bold;
            border: white;
            background: white;
        }
    </style>
    <script>
        function calc(flag){
            var num1=document.getElementById("num1").value*1;//获取第一个文本框中的值
            var num2=document.getElementById("num2").value*1;//获取第二个文本框中的值
            var resultDom=document.getElementById("result");//获取结果的DOM对象
            var result;
            if(flag=="+"){
                result=num1+num2;
            }else if(flag=="-"){
                result=num1-num2;
            }else if(flag=="*"){
                result=num1*num2;
            }else{
                result=num1/num2;
            }
            resultDom.value=result;
        }
        function doClear(){
           var num1Dom =document.getElementById("num1");//获取元素的DOM对象
           var num2Dom =document.getElementById("num2");
           var resultDom=document.getElementById("result");
           num1Dom.value="";
           num2Dom.value="";
           resultDom.value="";

        }
    </script>

</head>

<body>
    <div class="a1">
        <div class="a2">计算器</div>
        <div class="a3">
            <div class="a4">
                <div class="a5">第一个数：</div>
                <div>
                    <input type="text" class="a6" id="num1" value="">
                </div>
            </div>
            <div class="b3">
                <div class="b1">第二个数：</div>
                <div>
                    <input type="text" class="b2" id="num2" value="">
                </div>
            </div>
            <div>
                <div class="b4">
                    <div>
                        <input type="button" value="+" class="b5" onclick="calc('+')">
                    </div>
                    <div>
                        <input type="button" value="-" class="b5" onclick="calc('-')">
                    </div>
                    <div>
                        <input type="button" value="*" class="b5" onclick="calc('*')">
                    </div>
                    <div>
                        <input type="button" value="/" class="b5" onclick="calc('/')">
                    </div>
                </div>
                <div class="c1">
                    <div class="c2">结果：</div>
                    <div>
                        <input type="text" class="c3" id="result" value="">
                    </div>
                </div>
                <div class="c4">
                    <div>
                        <input type="button" value="清空" class="c5" value="" onclick="doClear()">
                    </div>
                </div>
            </div>
        </div>
    </div>


</body>

</html>